<?php
/**
 * Created by JetBrains PhpStorm.
 * User: cgp
 * Date: 13-5-13
 * Time: 上午10:49
 * 消息系统
 * /d/jh
 */
$did = $_SESSION['sid'];
$dtype = $_SESSION['dtype'];
if(!$did) {
    exit('未登录或登录超时！');
}
include '../common/autoload.php';
use pft\Member\MemberAccount;
use \pft\notice;


$act = $_REQUEST['todo'];
$notice = new notice();
$mem = new MemberAccount($GLOBALS['le'], $did, SoapInit::GetSoapInside());
//$lvl = $m_info['lvl'];
switch($act) {
    case 'create':
//        print_r($_REQUEST);exit;
        $title = safetxt($_REQUEST['title']);
        $content = safehtml($_REQUEST['content']);
        $sms_notify = 0;
        $status = 1;
        $px = 0;
        if(!empty($_REQUEST['sendsms'])) {
            $sms_notify = 1;
        }
        $et = trim($_REQUEST['et']);

        if(!empty($et) && !checkData($et)) {
            exit('{"msg":"到期日期格式错误！"}');
        }
        if(!empty($et) && date('Y-m-d') > $et) {
            exit('{"msg":"到期日期不能小于当天日期"}');
        }

        $len = mb_strlen($content,'utf-8');
        if(!$len) {
            exit('{"msg":"通知内容不能为空"}');
        }
        elseif($len>20000) {
            exit('{"msg":"通知内容不能超过20000个字符"}');
        }

        if(!empty($_REQUEST['lnkprods'])) {
            $lnkprods = implode(',', $_REQUEST['lnkprods']);
        }

        $res = $notice->AddNotice($title, $content, $status, $px,
            $did, $sms_notify, $et,$lnkprods, $mem);
        echo json_encode($res);
        break;
    case 'update':
        $nid = $_POST['nid'];
        $state = abs($_POST['state']);
        $res = $notice->SetNoticeStatus($nid, $did,$state, $dtype);
        echo $res;
        break;
    case 'verify':
        $nid = $_POST['nid'];
        $status = abs($_POST['status']);
        $res = $notice->SetNoticeStatusByAdmin($nid, $status);
        echo $res;
        break;
    case 'countResiver':
        $sendTo=abs($_GET['resiver']);
        $oid=abs($_GET['oid']);
        echo $mem->CountResiver($did, $sendTo);
        break;
    default:break;
}

